using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Globalization;

public partial class Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(IsPostBack)
        {
            if (Session["dt"]!=null)
            {
            RadGrid1.DataSource = ((DataTable)Session["dt"]).DefaultView;
            RadGrid1.Columns[0].HeaderText = "Producto";
            RadGrid1.Columns[1].HeaderText = "Categoria";
            RadGrid1.Columns[2].HeaderText = "Proveedor";           
            }
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ServiceReference1.Product[] ProductList = new ServiceReference1.SampleServiceNameClient().ReadAllProducts();

        // Create a DataTable instance
        DataTable dTbl = new DataTable("myDynamicTable");

        // Create a DataColumn instances

        DataColumn dcProducto = new DataColumn();
        DataColumn dcCategoria = new DataColumn();
        DataColumn dcProveedor = new DataColumn();

        dcProducto.ColumnName = "Producto";
        dcProducto.DataType = Type.GetType("System.String");

        dcCategoria.ColumnName = "Categoria";
        dcCategoria.DataType = Type.GetType("System.String");

        dcProveedor.ColumnName = "Proveedor";
        dcProveedor.DataType = Type.GetType("System.String"); 


        // Add these DataColumns into the DataTable

        dTbl.Columns.Add(dcProducto);
        dTbl.Columns.Add(dcCategoria);
        dTbl.Columns.Add(dcProveedor);

        foreach(ServiceReference1.Product p in ProductList)
        {
            // Create a DataRow Instance from the table we create above, with NewRow();
            DataRow myrow = dTbl.NewRow();

            myrow["Producto"] = p.ProductName;
            myrow["Categoria"] = p.Category.CategoryName;
            myrow["Proveedor"] = p.Supplier.CompanyName;
            // Add the row into the table
            dTbl.Rows.Add(myrow);        
        }

        DataSet ds = new DataSet("dsProducto");
        ds.Tables.Add(dTbl);

        RadGrid1.DataSource = dTbl.DefaultView;
        RadGrid1.Columns[0].HeaderText = "Producto";
        RadGrid1.Columns[1].HeaderText = "Categoria";
        RadGrid1.Columns[2].HeaderText = "Proveedor";

        Session["dt"] = dTbl;

        RadGrid1.DataBind();

    }

    protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
            RadGrid1.Culture = new CultureInfo(e.Value.ToString());
            
            RadGrid1.Rebind();
    }
    protected void btnNuevo_Click(object sender, EventArgs e)
    {

    }
}
